package pl.edu.mimuw.irs.rcp.controller.editor.roles.command;

import java.util.LinkedHashMap;
import java.util.Map;

import pl.edu.mimuw.irs.core.model.design.net.IRSWorkflow;
import pl.edu.mimuw.irs.core.model.design.resource.Requirement;
import pl.edu.mimuw.irs.core.model.design.resource.Role;
import pl.edu.mimuw.irs.core.model.design.resource.RoleInstance;

public class DeleteWorkflowRoleCommand extends AbstractWorkflowRoleCommand {

	// *** Attributes

	private Map<Requirement, RoleInstance> affectedInstances;
	public Map<Requirement, RoleInstance> getAffectedInstances() {
		return affectedInstances;
	}
	
	// *** Constructors

	public DeleteWorkflowRoleCommand(IRSWorkflow workflow, Role role) {
		super(workflow, role);
		this.affectedInstances = new LinkedHashMap<Requirement, RoleInstance>();
		for (Requirement requirement : getAffectedRequirements()) {
			RoleInstance instance = requirement.getRolesMap().get(getRole());
			affectedInstances.put(requirement, instance);
		}
	}
	
	// *** Methods

	@Override
	protected void execute(Requirement requirement) {
		requirement.remove(getRole());
	}
	
	@Override
	protected void undo(Requirement requirement) {
		RoleInstance instance = getAffectedInstances().get(requirement);
		requirement.add(instance);
	}
}
